<?php

class Toolbase {
        
        public static function addStat( $tool ) {
                
                $db = ToolbaseDatabaseManager::getInstance();
                $db = $db->getServerFromName( 'sql', 'u_cyberpower678' );
                
                if( !$db || !$db->getObject() ) return;
                $db = $db->getObject();
                
                $fullurl = "http://toolserver.org".$_SERVER['REQUEST_URI'];
                $referer = @$_SERVER['HTTP_REFERER'];
                $agent = @$_SERVER['HTTP_USER_AGENT'];
                
        if( $referer == "" ) $referer = "Direct";
        
        $res = $db->insert(
                        'stats',
                        array(
                                'tool' => $tool,
                                'ip' => $_SERVER['REMOTE_ADDR'],
                                'referer' => $referer,
                                'date' => date('l jS \of F Y h:i:s A'),
                                'agent' => $agent,
                                'url' => $fullurl
                        )
                );
                
                $id = $db->lastInsertId();
                
                return $res;
        
        }
        
        public static function getPossibleLanguages() {
                $dirs = array_map( 'basename', sfFinder::type('dir')->in( sfConfig::get( 'sf_app_i18n_dir' ) ) );
                $dirs[] = 'en';
                        
                sort( $dirs );
                return $dirs;
        }
        
        public static function cleanUsername( $name ) {
        
                $name = trim( str_replace( array('&#39;','%20'), array('\'',' '), $name ) );
                $name = urldecode($name);
                $name = str_replace('_', ' ', $name);
                $name = ucfirst( $name );
                
                return $name;
        }
        
}
